﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Itop.YHPC.BLL;
using Itop.YHPC.Model;
using System.Collections.Generic;

namespace Itop.YHPC.controller
{
    public class workflowController
    {
        static sysprogBLL progbll;
        static yhpcMainBLL mainbll;
        static yhpcDictionaryBLL dictbll;
        static yhpcOrgBLL orgbll;
        static yhpcWfBLL wfbll;

        public static sysprogBLL ProgBll
        {
            get
            {
                if (progbll == null)
                    progbll = Global.GetService<sysprogBLL>();
                return workflowController.progbll;
            }
        }
        public static yhpcMainBLL MainBLL
        {
            get
            {
                if (mainbll == null)
                    mainbll = Global.GetService<yhpcMainBLL>();
                return workflowController.mainbll;
            }
        }
        public static yhpcDictionaryBLL DictBLL
        {
            get
            {
                if (dictbll == null)
                    dictbll = Global.GetService<yhpcDictionaryBLL>();
                return workflowController.dictbll;
            }
        }
        public static yhpcOrgBLL OrgBLL
        {
            get
            {
                if (orgbll == null)
                    orgbll = Global.GetService<yhpcOrgBLL>();
                return workflowController.orgbll;
            }
        }
        public static yhpcWfBLL WfBLL
        {
            get
            {
                if (wfbll == null)
                    wfbll = Global.GetService<yhpcWfBLL>();
                return workflowController.wfbll;
            }
        }

        public static IList<sysprog> GetProgList(string where)
        {
            return ProgBll.SelectByWhere(where);
        }

        public static IList<yhpcMain> GetMainList(string where)
        {
            return MainBLL.SelectByWhere(where);
        }

        public static yhpcMain GetMain(string id)
        {
            return MainBLL.Get(id);
        }

        public static void Insert(yhpcMain main)
        {
            MainBLL.Insert(main);
        }

        public static void Update(yhpcMain main)
        {
            MainBLL.Update(main);
        }
        public static void Delete(yhpcMain main)
        {
            MainBLL.Delete(main.id);
        }
        public static int GetMaxNo()
        {
            return MainBLL.GetMaxRowCount();
        }

        public static int GetMainRowCount(string sql)
        {
            return MainBLL.GetRowCount(sql);
        }

        public static IList<yhpcDictionary> GetDictList(string where)
        {
            return DictBLL.SelectByWhere(where);
        }
        public static int GetMaxOrderid(string type)
        {
            IList<yhpcDictionary> list = DictBLL.SelectByWhere(" where type='"+type+"' and orderid=(select Max(orderid) from yhpcDictionary)");
            if (list.Count > 0)
                return list[0].orderID;
            else
                return 0;
        }

        public static IList<yhpcOrg> GetOrgList(string where)
        {
            return OrgBLL.SelectByWhere(where);
        }

        public static yhpcWf GetWf(string id)
        {
            return WfBLL.SelectByWhere("where id='" + id + "'")[0];
        }



    }
}
